/* Copyright 2011 Brian Cairns
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.wsnetwork.reforger;

final public class ReforgingOption {
    private final Item item;
    private final StatVector delta;
    private final int toStatIndex;
    private final int fromStatIndex;
    private final int deltaValue;

    ReforgingOption(Item item, StatVector delta) {
        this.item = item;
        this.delta = delta;
        int[] deltaValues = delta.getData();
        int toStatIndex = 0;
        int fromStatIndex = 0;
        int deltaValue = 0;
        for (int i = 0; i < deltaValues.length; ++i) {
            if (deltaValues[i] < 0) { fromStatIndex = i;}
            if (deltaValues[i] > 0) {
                toStatIndex = i;
                deltaValue = deltaValues[i];
            }
        }
        this.toStatIndex = toStatIndex;
        this.fromStatIndex = fromStatIndex;
        this.deltaValue = deltaValue;
    }

    public Item getItem() {
        return item;
    }

    public StatVector getDelta() {
        return delta;
    }

    public int getDeltaValue() {
        return deltaValue;
    }

    @Override public String toString() {
        StringBuffer result = new StringBuffer();
        result.append("[\"");
        result.append(item.getSlotName());
        result.append(" ");
        result.append(item.getName());
        result.append("\" ");
        for (Stat stat : Stat.possibleStats) {
            if (delta.getStat(stat) < 0) {
                result.append(-1 * delta.getStat(stat));
                result.append(" ");
                result.append(stat.getName());
                break;
            }
        }
        result.append(" to ");
        for (Stat stat : Stat.possibleStats) {
            if (delta.getStat(stat) > 0) {
                result.append(stat.getName());
            }
        }
        result.append("]");
        return result.toString();
    }

    public int getToStatIndex() {
        return toStatIndex;
    }

    public int getFromStatIndex() {
        return fromStatIndex;
    }
}